<?php
namespace app\m\controller;
use x\Xbase;
use x\Container;
class Base extends Xbase{
    public $userinfo = [];
    public $com = [];
    public $sys = [];
    public $goodscat = [];
    public function __construct(){
        parent::__construct();
        if(!is_phone()){
            $url = env('domain')[MAIN_DOMAIN]['client']['pc'];
            r($url);
        }
        clear_cookie_arr('js');
        $this->_sys();
        $this->_user();
    }

    //验证登陆
    public function _user(){
        $user = m('User','c');
        $this->userinfo = $user->isLogin();
        $this->assign('userinfo',$this->userinfo);
    }

    //通用
    public function _sys(){
        $this->sys = m('Deploy','xcom')->lists();
        $this->assign('sys',$this->sys);
        $this->assign('m',$this->m);
        $this->assign('c',$this->c);
        $this->assign('a',$this->a);

        //是否关闭网站
        if(isset($this->sys['close_msg']) && !empty($this->sys['close_msg'])){
            header("Content-type:text/html;charset=utf-8");
            exit($this->sys['close_msg']);
        }


        //购物车数量
        $carts = get_cookie_arr("cart");
        $cart_list = [];
        $ids = [];
        foreach($carts as $k => $v){
            $cart = explode("|", $v);
            if(isset($cart[1])){
                $ids[] = $cart[1];
            }
        }
        $cart_count = count($ids);
        $this->assign("cart_count",$cart_count);

        $word = $this->db->cache("select * from word");
        foreach ($word as $key => $val) {
            $word[$val['uuid']] = $val;
            unset($word[$key]);
        }
        $this->com['word'] = $word;
        $this->assign('com',$this->com);
    }

    //验证登录
    public function checkLogin(){
        if($this->c=='publics')
            return true;

        if(!$this->userinfo){
            if(is_ajax()){
                err('请先登录!');
            }else{
                r(url('publics/login'));
            }
        }
    }

}
